//home模块仓库
import { reqCategoryList, reqGetBannerList, reqFloorList } from '@/api/index'

// state:仓库(存储数据的地方)
const state = {
  categoryList: [],
  bannerList: [],
  floorList: []
}
// mutations:修改state的唯一手段
const mutations = {
  CATEGORYLIST(state, categoryList) {
    state.categoryList = categoryList
  },
  BANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  FLOORLIST(state, floorList) {
    state.floorList = floorList
  }
}
// actions:处理state，可以书写自己的业务逻辑，也可以处理异步
const actions = {
  async categoryList({ commit }) {
    let result = await reqCategoryList()
    if (result.code == 200) {
      commit('CATEGORYLIST', result.data)
    }
  },

  async getBannerList({ commit }) {
    let result = await reqGetBannerList()
    commit('BANNERLIST', result.data)
  },

  async getFloorList({ commit }) {
    let result = await reqFloorList()
    commit('FLOORLIST', result.data)
  }
}
// getters:理解为(计算属性)，用于简化仓库数据，让组件获取仓库的数据更加方便
const getters = {}

export default {
  state,
  mutations,
  actions,
  getters
}
